package cn.zucc.edu.bruce.iot.send;



import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.zucc.edu.bruce.iot.DataDeal;

public class SendIOTData implements Serializable {
    private int header = 0xfffffffe;
    private String sno = "31701024";
    private short heartbeat;
    private char iotId = 19;
    private int sensorNum = 2;
    private List<SendDecData> sendDecData = new ArrayList<>(2);
    private byte checksum;
    private int end = 0xeffffffe;

    public byte[] getBytes() {
        byte[] bytes = new byte[56];
        System.arraycopy(DataDeal.intToBytes(0xfeffffff), 0, bytes, 0, 4);
        System.arraycopy(DataDeal.stringToBytes(this.sno), 0, bytes, 4, 8);
        System.arraycopy(DataDeal.shortToBytes(this.heartbeat), 0, bytes, 12, 2);
        bytes[14] = DataDeal.charToByte(iotId);
        System.arraycopy(DataDeal.intToBytes(sensorNum), 0, bytes, 15, 4);
        System.arraycopy(this.sendDecData.get(0).getDecBytes(), 0, bytes, 19, 16);
        System.arraycopy(this.sendDecData.get(1).getDecBytes(), 0, bytes, 35, 16);
        checksum = DataDeal.setCheckSum(bytes);
        bytes[51] = checksum;
        System.arraycopy(DataDeal.intToBytes(end), 0, bytes, 52, 4);

        return bytes;
    }

    public void setHeader(int header) {
        this.header = header;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public void setHeartbeat(short heartbeat) {
        this.heartbeat = heartbeat;
    }

    public void setIotId(char iotId) {
        this.iotId = iotId;
    }

    public void setSensorNum(int sensorNum) {
        this.sensorNum = sensorNum;
    }

    public void setChecksum(byte checksum) {
        this.checksum = checksum;
    }

    public byte getChecksum() {
        return checksum;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public List<SendDecData> getSendDecData() {
        return sendDecData;
    }

    public void setSendDecData(List<SendDecData> sendDecData) {
        this.sendDecData = sendDecData;
    }
}
